#include "Assert.h"

#include "Test.h"

namespace {
	class RunnableMock : public Runnable {
	public:
		bool throwException;
		int callCount;
		bool recordMode;
		RunnableMock(bool throwException) {
			this->throwException = throwException;
			recordMode = true;
		}
		virtual void run() {
			if (throwException) {
				throw 0;
			}
			if (recordMode) {
				callCount++;
			}
			else {
				callCount--;
			}
		}
		void recordFinished() {
			recordMode = false;
		}
		void verify() {
			if (callCount != 0) {
				throw 0;
			}
		}
	};
	class TestLoggerMock : public TestLogger {
		void printSuite(string suiteName) {
		}
		void printTest(Test test) {
		}
		void end() {
		}
	};

	RunnableMock* runnable;
	RunnableMock* runnableWithException;
	TestContainer* testContainer;
	
	Test* test1;
	Test* test2;
	Test* test3;

	TestLogger* testLoggerMock;
	TestRunner* testRunner;

	BEFORE {
		runnable = new RunnableMock(false);
		runnableWithException = new RunnableMock(true);

		test1 = new Test;
		test1->name = "test1";
		test1->runnable = runnable;

		test2 = new Test;
		test2->name = "test2";
		test2->runnable = runnable;

		test3 = new Test;
		test3->name = "test3";
		test3->runnable = runnableWithException;

		testContainer = new TestContainer();

		testContainer->addTest("suite1", *test1);
		testContainer->addTest("suite1", *test2);
		testContainer->addTest("suite2", *test3);

		testLoggerMock = new TestLoggerMock();
		testRunner = new TestRunner(*testLoggerMock);
	}

	AFTER {
		delete runnable;
		delete runnableWithException;

		delete test1;
		delete test2;
		delete test3;

		delete testContainer;

		delete testLoggerMock;
		delete testRunner;
	}

	TEST(T1) {
		// expectatuins

		testLoggerMock->printSuite("suite1");

//		testLoggerMock->recordFinished();

		testRunner->run(*testContainer);

		// verify
//		testLoggerMock->verify();
	}
}